
public class Main {
public String longestPalindrome(String s) {
        int size = s.length();
        int max = 0;
        String result = "";
        for (int i = 0; i < size; i++) {
            for (int j = size; j > 0; j--) {
                String str = s.substring(i, j);
                if (str.length() <= max) {
                    break;
                }
                int left = 0;
                int right = str.length() - 1;
                boolean flag = false;
                while (left <= right) {
                    if (str.charAt(left) != str.charAt(right)) {
                        break;
                    }
                    if (left + 1 == right || left == right) {
                        flag = true;
                        if (str.length() > max) {
                            result = str;
                        }
                    }
                    left++;
                    right--;
                }
                if (flag && result.length() >= max) {
                    max = result.length();
                    break;
                }
            }
        }
        return result;
    }
}

